#include "Game2DMap.h"
Game2DMap::Game2DMap(int nummap)
{
	_numberMap = nummap;
	LoadMap("Maps/MapI.map");
}
Game2DMap::~ Game2DMap()
{

}
void Game2DMap::LoadMap(char *path)
{
	// line 1 : info map
	// line 2: info Main character
	// line 3-> n : object
	ifstream f(path);
	if(f.is_open())
	{
		int line = 0;
		int _typeObj;
		int _kindOf_typeObj ;
		int x;
		int y;
		int _typeBonus;
		_tree=new QuadTree(1000,500);
		_mainCharacter=new MainCharacter(0,0,0,_tree);
		while (!f.eof())
		{
			Object *Ob=NULL;
			if(line == 0)
			{
				f>>_widthOfMap>>_heightOfMap>>_numberMap;
			}else if(line == 1)
			{
				f>>_mainCharacter->_pRECT->left>>_mainCharacter->_pRECT->top>>_mainCharacter->level>>_mainCharacter->life>>_mainCharacter->scores;
			}else
			{
				f>>_typeObj>>_kindOf_typeObj>>x>>y>>_typeBonus;
				switch (_typeObj)
				{
				case Static_Object:
					Ob = new StaticObject(x,y,_kindOf_typeObj,_typeBonus,_tree);
					break;
				case Move_Object:
					Ob = new MoveObject(x,y,_tree,_kindOf_typeObj);
					break;
				case Bonus_Object:
					Ob = new Bonus(x,y,_tree,_kindOf_typeObj);
					break;
				}
			}
			if(Ob != NULL)
				_tree->AddObj(_tree->_root,Ob);
			f.ignore();
			line ++;
		}
		f.close();
	}
}
void Game2DMap::InitSightMap(int world)
{
	
}
void Game2DMap::Draw()
{
	
	RECT rect;
	rect.top = rect.left = 0;
	rect.right = 100;
	rect.bottom = WINDOW_HEIGHT;
	_tree->DrawObj(0,rect);
}